/**
 *Copyright (c) 2024 - 2025 Midea Company of Midea Group.
 *
 * File Name 	      : ui_common.h
 * Author 	          : huocy
 * Date:              : 2024-12-25 15:01:00
 * Des:               : 
 */

#ifndef _UI_COMMON_H_INCLUDED_
#define _UI_COMMON_H_INCLUDED_

#include "lvgl.h"
// #include "model/ui_street_lamp.h"
#include <stdio.h>
#include "sys_cfg.h"
#include "font_manager.h"

void ui_printf(const char *format, ...);

#if CONFIG_SOC_BK7258
#define MLOG_D(format, ...) bk_printf(format "\n", ##__VA_ARGS__)
#define MLOG_I(format, ...) bk_printf(format "\n", ##__VA_ARGS__)
#define MLOG_W(format, ...) bk_printf(format "\n", ##__VA_ARGS__)
#define MLOG_E(format, ...) bk_printf(format "\n", ##__VA_ARGS__)
#else
// #include "midea/log.h"
#endif

// #include "font_manager.h"
// #include "data/ui_table_lamp_data_cache.h"
// #include "service/ui_table_lamp_service.h"

#define UI_DEBUG 1
#if CONFIG_SOC_BK7258
#define MIDEA_RES_PATH_PREFIX "/spi/res/"
#else
#define MIDEA_RES_PATH_PREFIX "./build/output/install/etc/midea_gw/ui_service/res/"
#endif

#define MIDEA_MAX_PATH_LEN 256

/// @brief ui_safe_set_font
int midea_ui_safe_set_font(lv_obj_t* obj, FONT_TYPE type, uint16_t weight);

/// @brief ui safe add flag
/// @param obj 
/// @param f 
/// @return 
bool midea_ui_safe_add_flag(lv_obj_t * obj, lv_obj_flag_t f);

/// @brief ui safe clear flag
/// @param obj 
/// @param f 
/// @return 
bool midea_ui_safe_clear_flag(lv_obj_t * obj, lv_obj_flag_t f);

/// @brief ui safe del obj
bool midea_ui_safe_del_obj(lv_obj_t * obj);

/// @brief ui set img src
int midea_ui_set_img_src(lv_obj_t * obj,char* name_str);

/// @brief ui safe set size
int midea_ui_safe_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h);

/// @brief ui safe set pos
int midea_ui_safe_obj_align(lv_obj_t * obj, lv_align_t align, lv_coord_t x_ofs, lv_coord_t y_ofs);

/// @brief ui safe remove style all
int midea_ui_safe_remove_style_all(lv_obj_t * obj);

/// @brief ui safe set text
int midea_ui_safe_set_text(lv_obj_t * obj, char* text);


void midea_ui_safe_del_obj_async(lv_obj_t * obj);

/// @brief ui get pic file path
void midea_get_picfile_path(char* path, int pathLen, char* name);

/// @brief ui get wstr len ex:chinese 2~6 byte
int midea_ui_util_get_wstr_len(char* name_str);

/// @brief ui safe get label text
char *midea_ui_safe_get_text(lv_obj_t * obj);

/// @brief ui safe del timer
int midea_ui_safe_del_timer(lv_timer_t *timer);

///  @brief ui safe create timer with cb and time
lv_timer_t *midea_ui_safe_create_timer(lv_timer_cb_t timer_xcb, uint32_t period, void * user_data);

static uint8_t utf8_code_bytes(uint8_t byte);

int ui_util_get_wstr_len(char* name_str);

void ui_util_sub_pre_wstr(char* name_str, int toIndex, char** output);

void ui_util_sub_subfix_wstr(char* name_str, int fromIndex, char** output);

#endif  /* End #ifndef _UI_COMMON_H_INCLUDED_ */

